// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   AbstractChart.java

package org.achartengine.chart;

import android.graphics.*;
import java.io.Serializable;
import java.util.List;
import org.achartengine.model.Point;
import org.achartengine.model.SeriesSelection;
import org.achartengine.renderer.*;

public abstract class AbstractChart
	implements Serializable
{

	public AbstractChart()
	{
	}

	public abstract void draw(Canvas canvas, int i, int j, int k, int l, Paint paint);

	protected void drawBackground(DefaultRenderer defaultrenderer, Canvas canvas, int i, int j, int k, int l, Paint paint, 
			boolean flag, int i1)
	{
		if (defaultrenderer.isApplyBackgroundColor() || flag)
		{
			if (flag)
				paint.setColor(i1);
			else
				paint.setColor(defaultrenderer.getBackgroundColor());
			paint.setStyle(android.graphics.Paint.Style.FILL);
			canvas.drawRect(i, j, i + k, j + l, paint);
		}
	}

	protected int drawLegend(Canvas canvas, DefaultRenderer defaultrenderer, String as[], int i, int j, int k, int l, 
			int i1, int j1, Paint paint, boolean flag)
	{
		float f = 32F;
		if (defaultrenderer.isShowLegend())
		{
			float f1 = i;
			float f2 = (float)((k + i1) - j1) + f;
			paint.setTextAlign(android.graphics.Paint.Align.LEFT);
			paint.setTextSize(defaultrenderer.getLegendTextSize());
			int k1 = Math.min(as.length, defaultrenderer.getSeriesRendererCount());
			for (int l1 = 0; l1 < k1; l1++)
			{
				float f3 = getLegendShapeWidth(l1);
				String s = as[l1];
				if (as.length == defaultrenderer.getSeriesRendererCount())
					paint.setColor(defaultrenderer.getSeriesRendererAt(l1).getColor());
				else
					paint.setColor(0xffcccccc);
				float af[] = new float[s.length()];
				paint.getTextWidths(s, af);
				float f4 = 0.0F;
				float af1[] = af;
				float f6 = af1.length;
				for (int i2 = 0; i2 < f6; i2++)
				{
					float f8 = af1[i2];
					f4 += f8;
				}

				float f5 = f3 + 10F + f4;
				f6 = f1 + f5;
				if (l1 > 0 && getExceed(f6, defaultrenderer, j, l))
				{
					f1 = i;
					f2 += defaultrenderer.getLegendTextSize();
					f += defaultrenderer.getLegendTextSize();
					f6 = f1 + f5;
				}
				if (getExceed(f6, defaultrenderer, j, l))
				{
					float f7 = (float)j - f1 - f3 - 10F;
					if (isVertical(defaultrenderer))
						f7 = (float)l - f1 - f3 - 10F;
					int j2 = paint.breakText(s, true, f7, af);
					s = (new StringBuilder()).append(s.substring(0, j2)).append("...").toString();
				}
				if (!flag)
				{
					drawLegendShape(canvas, defaultrenderer.getSeriesRendererAt(l1), f1, f2, l1, paint);
					canvas.drawText(s, f1 + f3 + 5F, f2 + 5F, paint);
				}
				f1 += f5;
			}

		}
		return Math.round(f + defaultrenderer.getLegendTextSize());
	}

	protected boolean getExceed(float f, DefaultRenderer defaultrenderer, int i, int j)
	{
		boolean flag = f > (float)i;
		if (isVertical(defaultrenderer))
			flag = f > (float)j;
		return flag;
	}

	protected boolean isVertical(DefaultRenderer defaultrenderer)
	{
		return (defaultrenderer instanceof XYMultipleSeriesRenderer) && ((XYMultipleSeriesRenderer)defaultrenderer).getOrientation() == org.achartengine.renderer.XYMultipleSeriesRenderer.Orientation.VERTICAL;
	}

	protected void drawPath(Canvas canvas, float af[], Paint paint, boolean flag)
	{
		Path path = new Path();
		path.moveTo(af[0], af[1]);
		for (int i = 2; i < af.length; i += 2)
			path.lineTo(af[i], af[i + 1]);

		if (flag)
			path.lineTo(af[0], af[1]);
		canvas.drawPath(path, paint);
	}

	public abstract int getLegendShapeWidth(int i);

	public abstract void drawLegendShape(Canvas canvas, SimpleSeriesRenderer simpleseriesrenderer, float f, float f1, int i, Paint paint);

	private String getFitText(String s, float f, Paint paint)
	{
		String s1 = s;
		int i = s.length();
		int j;
		for (j = 0; paint.measureText(s1) > f && j < i; s1 = (new StringBuilder()).append(s.substring(0, i - j)).append("...").toString())
			j++;

		if (j == i)
			s1 = "...";
		return s1;
	}

	protected int getLegendSize(DefaultRenderer defaultrenderer, int i, float f)
	{
		int j = defaultrenderer.getLegendHeight();
		if (defaultrenderer.isShowLegend() && j == 0)
			j = i;
		if (!defaultrenderer.isShowLegend() && defaultrenderer.isShowLabels())
			j = (int)((defaultrenderer.getLabelsTextSize() * 4F) / 3F + f);
		return j;
	}

	protected void drawLabel(Canvas canvas, String s, DefaultRenderer defaultrenderer, List list, int i, int j, float f, 
			float f1, float f2, float f3, int k, int l, Paint paint)
	{
		if (defaultrenderer.isShowLabels())
		{
			paint.setColor(defaultrenderer.getLabelsColor());
			double d = Math.toRadians(90F - (f2 + f3 / 2.0F));
			double d1 = Math.sin(d);
			double d2 = Math.cos(d);
			int i1 = Math.round((float)i + (float)((double)f * d1));
			int j1 = Math.round((float)j + (float)((double)f * d2));
			int k1 = Math.round((float)i + (float)((double)f1 * d1));
			int l1 = Math.round((float)j + (float)((double)f1 * d2));
			float f4 = defaultrenderer.getLabelsTextSize();
			float f5 = Math.max(f4 / 2.0F, 10F);
			paint.setTextAlign(android.graphics.Paint.Align.LEFT);
			if (i1 > k1)
			{
				f5 = -f5;
				paint.setTextAlign(android.graphics.Paint.Align.RIGHT);
			}
			float f6 = (float)k1 + f5;
			float f7 = l1;
			float f8 = (float)l - f6;
			if (i1 > k1)
				f8 = f6 - (float)k;
			s = getFitText(s, f8, paint);
			float f9 = paint.measureText(s);
			boolean flag1;
			for (boolean flag = false; !flag; flag = !flag1)
			{
				flag1 = false;
				int i2 = list.size();
				for (int j2 = 0; j2 < i2 && !flag1; j2++)
				{
					RectF rectf = (RectF)list.get(j2);
					if (rectf.intersects(f6, f7, f6 + f9, f7 + f4))
					{
						flag1 = true;
						f7 = Math.max(f7, rectf.bottom);
					}
				}

			}

			l1 = (int)(f7 - f4 / 2.0F);
			canvas.drawLine(i1, j1, k1, l1, paint);
			canvas.drawLine(k1, l1, (float)k1 + f5, l1, paint);
			canvas.drawText(s, f6, f7, paint);
			list.add(new RectF(f6, f7, f6 + f9, f7 + f4));
		}
	}

	public SeriesSelection getSeriesAndPointForScreenCoordinate(Point point)
	{
		return null;
	}
}
